Ninja Database Pro
Delete<T>(Int64) Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class > Delete Method : Delete<T>(Int64) Method
Delete an object from the database by the primary key The object must have a primary key property of Id or ObjectNameId as a type of long or an exception will be thrown. Example primary key: CustomerId
Syntax
Public Overloads Function Delete(Of T As {Class, New})( _
   ByVal primaryKey As Long _
) As Integer
Dim instance As NinjaDbPro
Dim primaryKey As Long
Dim value As Integer
 
value = instance.Delete(Of T)(primaryKey)
public int Delete<T>( 
   long primaryKey
)
where T: class, new()
public:
int Deletegeneric<typename T>
( 
   int64 primaryKey
) 
where T: ref class, gcnew()

Parameters

primaryKey

Type Parameters

T

Return Value

The number of items deleted
Example
NinjaDbPro db = new NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName");
             
            //Licensed Mode
            //db.UserName = "John Smith 101224";
            //db.LicenseKey = "aousdf832jasf==";
             
            //Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
            //db.Storage = new MemoryDatabase(); //In memory database
            //db.Storage = new FileDatabase();  
             
            List<long> keys = new List<long>();
             
            db.OpenDatabase();
            for (int i = 0; i < 1000; i++)
            {
                keys.Add(i + 1);
                Vendor vendor = new Vendor();
                vendor.Name = "Vendor " + i;
                db.Save(vendor);
            }
             
            //Do a bulk delete
            int recordsDeleted = db.Delete<Vendor>(keys.ToArray());
             
            //This will load no records since they were all deleted
            List<Vendor> vendors = db.LoadAll<Vendor>();
             
            db.CloseDatabase();
Dim db As New NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName")
             
            'Licensed Mode
            'db.UserName = "John Smith 101224";
            'db.LicenseKey = "aousdf832jasf==";
             
            'Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
            'db.Storage = new MemoryDatabase(); //In memory database
            'db.Storage = new FileDatabase();  
             
            Dim keys As New List(Of Long)()
             
            db.OpenDatabase()
            For i As Integer = 0 To 999
                keys.Add(i + 1)
                Dim vendor As New Vendor()
                vendor.Name = "Vendor " & i
                db.Save(vendor)
            Next i
             
            'Do a bulk delete
            Dim recordsDeleted As Integer = db.Delete(Of Vendor)(keys.ToArray())
             
            'This will load no records since they were all deleted
            Dim vendors As List(Of Vendor) = db.LoadAll(Of Vendor)()
             
            db.CloseDatabase()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NinjaDbPro Class
NinjaDbPro Members
Overload List